; Test cases for the for-each procedure

; Utility function for testing - displays values with a newline
(define display-with-newline
  (lambda (x)
    (display x)
    (newline)))

; Test 1: Basic usage with a single list
(display "Test 1: Basic for-each with a single list\n")
(for-each display-with-newline '(1 2 3 4 5))
(newline)

; Test 2: Using for-each to build a side-effect (sum)
(display "Test 2: Using for-each to accumulate a sum\n")
(define sum 0)
(for-each (lambda (x) (set! sum (+ sum x))) '(1 2 3 4 5))
(display "Sum: ")
(display sum)
(newline)
(newline)

; Test 3: Using for-each with multiple lists
(display "Test 3: for-each with multiple lists\n")
(define result '())
(for-each 
  (lambda (x y) 
    (set! result (cons (* x y) result)))
  '(1 2 3 4 5) 
  '(6 7 8 9 10))
(display "Results (reversed): ")
(display result)
(newline)
(newline)

; Test 4: for-each with a built-in procedure
(display "Test 4: for-each with a built-in procedure\n")
(define test-list '(a b c d e))
(display "Original list: ")
(display test-list)
(newline)
(display "Each element: ")
(for-each (lambda (x) (display x) (display " ")) test-list)
(newline)
(newline)

; Test 5: for-each with empty list
(display "Test 5: for-each with empty list\n")
(define was-called #f)
(for-each (lambda (x) (set! was-called #t)) '())
(display "Procedure was called: ")
(display was-called)
(newline)
(newline)

; Test 6: for-each with lists of different lengths
(display "Test 6: for-each with lists of different lengths\n")
(define count 0)
(for-each 
  (lambda (x y) 
    (set! count (+ count 1))
    (display "Pair ")
    (display count)
    (display ": ")
    (display x)
    (display " ")
    (display y)
    (newline))
  '(1 2 3 4 5) 
  '(a b c))  ; Shorter list
(newline)

(display "All tests completed!\n")